import 'package:flutter/material.dart';
import 'tabs/Home.dart';
import 'tabs/Category.dart';
import 'tabs/Setting.dart';

class Tabs extends StatefulWidget {
  final index;
  Tabs({Key key, this.index = 0}) : super(key: key);

  @override
  _TabsState createState() => _TabsState(this.index);
}

class _TabsState extends State<Tabs> {
  int _currentIndex = 0;
  _TabsState(index) {
    this._currentIndex = index;
  }

  List _pageList = [
    // 按这里的索引取值
    HomePage(),
    CategoryPage(),
    SettingPage()
  ];
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        appBar: AppBar(title: Text('container  text')),
        floatingActionButton: Container(
          height: 55,
          width: 55,
          // padding: EdgeInsets.all(4),
          margin: EdgeInsets.only(top: 5),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(40),
            color: Colors.white,
          ),
          child: FloatingActionButton(
            child: Icon(Icons.add),
            onPressed: () {
              setState(() {
                this._currentIndex = 1;
              });
            },
            backgroundColor: this._currentIndex == 1 ? Colors.red : Colors.blue,
          ),
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        body: this._pageList[this._currentIndex],
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: this._currentIndex, //  对应索引值
          onTap: (int index) {
            // print(index);
            setState(() {
              this._currentIndex = index;
            });
          },
          // iconSize: 36.0, // icon 大小
          fixedColor: Colors.red, // 选中颜色
          type: BottomNavigationBarType.fixed, // 默认三个tab， 设置这个可以有多个
          items: [
            BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('首页')),
            BottomNavigationBarItem(
                icon: Icon(Icons.category), title: Text('分类')),
            BottomNavigationBarItem(
                icon: Icon(Icons.settings), title: Text('设置')),
          ],
        ),
        drawer: Drawer(
          child: Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  Expanded(
                    //   child: DrawerHeader(
                    //     child: Text('hello'),
                    //     decoration: BoxDecoration(
                    //       image: DecorationImage(
                    //         image: NetworkImage("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_match%2F0%2F12068074343%2F0.jpg&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625843873&t=108e175cbc72983c9a9f06408afda6f4"),
                    //         fit: BoxFit.cover,
                    //       )
                    //     ),
                    //  )
                    child: UserAccountsDrawerHeader(
                      accountName: Text('ymf'),
                      accountEmail: Text('abc@qq.com'),
                      currentAccountPicture: CircleAvatar(
                        backgroundImage: NetworkImage(
                            'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg1.lukou.com%2Fstatic%2Fp%2Fblog%2Fmedium%2F0028%2F80%2F66%2F63%2F28806663.jpg&refer=http%3A%2F%2Fimg1.lukou.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625843873&t=76f6c21726cee0947f17f4356454446b'),
                      ),
                      decoration: BoxDecoration(
                          image: DecorationImage(
                        image: NetworkImage(
                            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_match%2F0%2F12068074343%2F0.jpg&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625843873&t=108e175cbc72983c9a9f06408afda6f4"),
                        fit: BoxFit.cover,
                      )),
                    ),
                  )
                ],
              ),
              ListTile(
                leading: CircleAvatar(
                  child: Icon(Icons.home),
                ),
                title: Text('我的空间'),
              ),
              Divider(),
              ListTile(
                leading: CircleAvatar(
                  child: Icon(Icons.home),
                ),
                title: Text('用户中心'),
                onTap: () {
                  Navigator.of(context).pop(); // 隐藏侧边栏
                  Navigator.pushNamed(context, '/user');
                },
              ),
              Divider(),
              ListTile(
                leading: CircleAvatar(
                  child: Icon(Icons.home),
                ),
                title: Text('我的空间3'),
              ),
            ],
          ),
        ),
        endDrawer: Drawer(
          child: Text('right'),
        ),
      ),
    );
  }
}
